package com.dinadi.yidi.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.dinadi.yidi.R;
import com.dinadi.yidi.bean.CommentRequest;
import com.dinadi.yidi.bean.ReplyListRequestEntity;
import com.dinadi.yidi.ui.activity.ReplyListActivity;
import com.dinadi.yidi.utils.FormatCurrentData;
import com.dinadi.yidi.utils.ImageUtils;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;

/**
 * author: JiaYu.He
 * Date: 2017/4/12
 * Time: 16:43
 */

public class ReplyListAdapter extends BaseAdapter {

    private Context context;
    private List<ReplyListRequestEntity> mList = new ArrayList<>();

    public ReplyListAdapter(Context context, List<ReplyListRequestEntity> mList) {
        this.context = context;
        this.mList = mList;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ReplyListAdapter.ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.adapter_daily_product_listview_item, null); /**这个是评论的item列表*/
            viewHolder = new ReplyListAdapter.ViewHolder();
            viewHolder.designer_nick_name = (TextView) convertView.findViewById(R.id.designer_nick_name);
            viewHolder.creat_time = (TextView) convertView.findViewById(R.id.creat_time);
            viewHolder.head_img = (ImageView) convertView.findViewById(R.id.head_img);
            viewHolder.content = (TextView) convertView.findViewById(R.id.content);
            viewHolder.repeat_total_count = (TextView) convertView.findViewById(R.id.repeat_total_count);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ReplyListAdapter.ViewHolder) convertView.getTag();
        }
        viewHolder.designer_nick_name.setText(mList.get(position).getFromUserName());
        String creatTime = mList.get(position).getCreateTime();
        String showCreatTime = FormatCurrentData.getTimeRange(creatTime);
        viewHolder.creat_time.setText(showCreatTime);

        String str=mList.get(position).getContent();
        try {
            str = URLDecoder.decode(str,"utf-8");
//            str = URLDecoder.decode(str,"utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        viewHolder.content.setText(str);
//        viewHolder.content.setText(mList.get(position).getContent());
        String imgUrl = mList.get(position).getFromHeadImg();
        if (!imgUrl.equals("")) {
            ImageUtils.loadImageView(context, imgUrl, viewHolder.head_img);
        } else {
            ImageUtils.loadImageView(context, R.drawable.me_img_default, viewHolder.head_img);
        }

        return convertView;
    }

    class ViewHolder {
        TextView designer_nick_name, creat_time, content, repeat_total_count;
        ImageView head_img;


    }
}

